package com.ews.onlineexchange.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.security.RolesAllowed;
import javax.enterprise.inject.Model;
import javax.inject.Inject;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;

import com.ews.onlineexchange.model.Bulletin;
import com.ews.onlineexchange.model.ContractRecord;
import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.model.ServiceBuyer;
import com.ews.onlineexchange.model.ServiceSupplier;
import com.ews.onlineexchange.model.Trade;
import com.ews.onlineexchange.model.User;
import com.ews.onlineexchange.service.EntityQuery;
import com.ews.onlineexchange.service.UserService;

@Model
@RolesAllowed(value = "buyer")
public class ContractRecordList extends EntityQuery<ContractRecord> {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;

	public ContractRecordList() {
		setMaxResults(MAX_RESULTS_NORMAL);
		setOrder("createDate desc");
	}

	

	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<ContractRecord> entity) {
		List<Predicate> restrictions = new ArrayList<Predicate>();
		restrictions.add(cb.equal(entity.get("delFlag"),DataEntity.DEL_FLAG_NORMAL));
		String projectName = (String)getParameterValues().get("projectName");
		if (!StringUtils.isBlank(projectName))
			restrictions.add(cb.like(entity.get("projectName"), getStringRestriction(projectName)));
		String supplierName = (String)getParameterValues().get("supplierName");
		if (!StringUtils.isBlank(supplierName))
			restrictions.add(cb.like(entity.get("supplierName"), getStringRestriction(supplierName)));
		
//		String serialNumber = (String)getParameterValues().get("serialNumber");
//		if (!StringUtils.isBlank(serialNumber))
//			restrictions.add(cb.like(entity.get("serialNumber"), getStringRestriction(serialNumber)));
		return restrictions;
	}


}
